//
//  GXShopPictureController.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/3.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXShopPictureController.h"
#import "GXShopPictureCell.h"
#import "GXShopAddPictureController.h"
@interface GXShopPictureController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * pictureTableView;
@property (nonatomic,strong)NSMutableArray * dataArray;
@end
static NSString * const shopPictureCell=@"GXShopPictureCell";
@implementation GXShopPictureController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"店铺实景图";
    self.view.backgroundColor = kGlobalbgColor;
    [self.view addSubview:self.pictureTableView];
    [self creatNavigationRightItem];
    [self requestdata];
}
- (void)requestdata
{
    [ShopAuthenticationManager selectShopRealPictureWithStoreID:StoreId success:^(id responseObject) {
        if (responseObject) {
            [self handleRequestServiceData:responseObject];
        }
        
    } fail:^(id responseObject) {
    }];
}
- (void)handleRequestServiceData:(id)responseObject
{
    NSString *dataStr = [NSString stringWithFormat:@"%@",responseObject[@"describa"]];
    if (![NSString isBlankString:dataStr]) {
        NSArray *array = [dataStr componentsSeparatedByString:@"-"];
        self.dataArray = [NSMutableArray arrayWithArray:array];
        [self.pictureTableView reloadData];
    }
    
}
- (void)creatNavigationRightItem
{
    UIButton * rightButton = [UIButton setButtonTitleNormal:@"新增" buttonTintColor:[UIColor whiteColor]];
    [rightButton addTarget:self action:@selector(clickRightItemButton:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
}

- (void)clickRightItemButton:(UIButton *)btn
{
    GXShopAddPictureController * addVC = [[GXShopAddPictureController alloc]init];
    addVC.changePictureBlock = ^(BOOL stateType) {
        [self requestdata];
    };
    [self.navigationController pushViewController:addVC animated:YES];
}
- (UITableView *)pictureTableView
{
    if (_pictureTableView == nil) {
        _pictureTableView = [[UITableView alloc] initWithFrame:CGRectMake(10,0,kUIScreenWidth-20,kUIScreenHeight-Height_TabBar-Height_StatusBar) style:UITableViewStyleGrouped];
        _pictureTableView.delegate=self;
        _pictureTableView.dataSource=self;
        _pictureTableView.sectionFooterHeight = 0.01f;
        _pictureTableView.sectionHeaderHeight= 15;
        _pictureTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
        _pictureTableView.showsHorizontalScrollIndicator=NO;
        _pictureTableView.showsVerticalScrollIndicator=NO;
        _pictureTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _pictureTableView.backgroundColor =kGlobalbgColor;
        [_pictureTableView  registerNib:[UINib nibWithNibName:@"GXShopPictureCell" bundle:nil] forCellReuseIdentifier:shopPictureCell];
    }
    return  _pictureTableView;
}

#pragma mark ---UITableViewDataSource UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GXShopPictureCell * cell = [tableView dequeueReusableCellWithIdentifier:shopPictureCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSString * imageStr = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.section]];
    cell.imageUrlStr = imageStr;
    cell.nameStr = [NSString stringWithFormat:@"店铺实景图%ld",indexPath.section +1];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 180;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * headerView = [[UIView alloc]init];
    headerView.backgroundColor = [UIColor clearColor];
    return headerView;
}

@end
